#pragma once
#include "FontGlyph.h"
namespace tge
{
	typedef CMap<WORD, WORD, CFontGlyph *, CFontGlyph *> WORD2Glyph;
	struct FontDesc
	{
		LONG lfEscapement;
		LONG lfOrientation;
		LONG lfWeight;
		BYTE lfItalic;
		BYTE lfUnderline;
		BYTE lfStrikeOut;
		BYTE lfCharSet;
		BYTE lfOutPrecision;
		BYTE lfClipPrecision;
		BYTE lfQuality;
		BYTE lfPitchAndFamily;
		TCHAR lfFaceName[LF_FACESIZE];
	public:
		FontDesc(const LOGFONT & lf);
		FontDesc();
		operator DWORD_PTR()
		{
			BYTE flag = (lfWeight / 100) | (lfItalic ? 16 : 0)
				| (lfUnderline ? 32 : 0)
				| (lfStrikeOut ? 64 : 0)
				| s_charsetindex[lfCharSet] * 12;

			WORD wLow = MAKEWORD(flag, lfFaceName[_tcslen(lfFaceName) - 1]);
			WORD wHigh = MAKEWORD(lfFaceName[0], lfFaceName[1]);
			return MAKELONG(wLow, wHigh);
		}
	private:
		static int s_charsetindex[256];
		friend class __FontGlyphManagerInit;
	};
	BOOL operator==(const FontDesc & fd1, const FontDesc & fd2);
	class CNormalizeFont
	{
	public:
		CNormalizeFont(const FontDesc & fontDesc);
		~CNormalizeFont(void);
		CFontGlyph * GetGlyph(WORD uChar);
	private:
		inline void POINTFX2GePoint2d(const POINTFX & pfx, GePoint2d & pt);
		CFont m_font;
		CDC m_dcMem;
		CFont *m_pOldFont;
		WORD2Glyph m_mapGlyph;
		double m_scaleFactor;
	};
	typedef CMap<FontDesc, FontDesc, CNormalizeFont*, CNormalizeFont *> FontDesc2FontPtr;
}